package com.yanze.schoolinformation.utils;

import android.content.Context;
import android.view.Gravity;
import android.widget.Toast;

import com.yanze.schoolinformation.app.App;

/**
 * Created by MrZheng on 2018/4/10.
 */

public class ToastUtils {

    private static Toast mToast;

    /**
     * show toast
     *
     * @param context context
     * @param msg     message
     */
    public static void show(Context context, String msg) {
        if (mToast == null) {
            mToast = Toast.makeText(context.getApplicationContext(), "", Toast.LENGTH_SHORT);
        }
        mToast.setText(msg);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();
    }

    /**
     * show toast
     *
     * @param msg message
     */
    public static void show(String msg) {
        if (mToast == null) {
            mToast = Toast.makeText(App.getMyApplication().getApplicationContext(), msg, Toast.LENGTH_SHORT);
        }
        mToast.setText(msg);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();
    }


    /**
     * show toast
     *
     * @param context context
     * @param msgId   message resource id
     */
    public static void show(Context context, int msgId) {
        if (mToast == null) {
            mToast = Toast.makeText(context.getApplicationContext(), "", Toast.LENGTH_SHORT);
        }
        mToast.setText(context.getString(msgId));
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();
    }

    /**
     * 长时间的吐司
     */
    public static void showToastLong(String msg) {
        if (mToast == null) {
            mToast = Toast.makeText(App.getMyApplication(), "", Toast.LENGTH_SHORT);
        }
        mToast.setDuration(Toast.LENGTH_LONG);
        mToast.setText(msg);
        mToast.setGravity(Gravity.CENTER, 0, 0);
        mToast.show();
    }
}
